using MallSystembackend.Api.Repository;
using MallSystembackend.Api.Model;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Linq;
using MallSystembackend.Api.ParamModel;
using Microsoft.AspNetCore.Http;
namespace MallSystembackend.Api.Controllers
{
    //发货地址
    public class ShipAddressControllers :ControllerBase
    {
        public IRepository<ShipAddress> _shipAddressRepository;
        public ShipAddressControllers(IRepository<ShipAddress> shipAddressRepository)
        {
            _shipAddressRepository = shipAddressRepository;
        }

        //添加发货地址
        [HttpPost]
        public ActionResult AddShipAddress(ParamShipAddressd model)
        {
            var address = new ShipAddress{
                MerchantId = model.MerchantId,
                ShipAddressOne = model.ShipAddressOne
            };

            _shipAddressRepository.Insert(address);

            return Ok(new{
                Code = 1000,
                Data = address,
                Msg = "添加地址成功"
            });
        }
        //根据店铺id获取所有发货地址
        [HttpGet("{id}")]
        public ActionResult GetAddressByShipId(int id)
        {
            var address = _shipAddressRepository.Table;
            var addressById = address.Where(x => x.MerchantId == id).ToList();

            return Ok(new{
                Code = 1000,
                Data = addressById,
                Msg = "获取成功"
            });
        }
    }
}